<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：tudougeaini
 邮箱：877873666@qq.com

 **** 版权所有 **** */



//用户检测
$MB->Open('','login',2);


switch ($mudi){
	case 'add':
		$menuFileID = 507;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'rev':
		$menuFileID = 508;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'del':
		$menuFileID = 509;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		del();
		break;

	default:
		die('err');
}

$MB->Close();
$DB->Close();





// 添加与修改
function AddOrRev(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN;

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$dataID			= OT::PostInt('dataID');

	$type			= OT::PostStr('type');
	$theme			= OT::PostStr('theme');
	$qq				= OT::PostStr('qq');
	$note			= OT::PostStr('note');
	$rank			= OT::PostInt('rank');
	$state			= OT::PostInt('state');

	if ($theme==''){
		JS::AlertBackEnd('表单内容接收不全');
	}

	$record=array();
	$record['VDL_type']			= $type;
	$record['VDL_theme']		= $theme;
	$record['VDL_qq']			= $qq;
	$record['VDL_note']			= $note;
	$record['VDL_rank']			= $rank;
	$record['VDL_state']		= $state;

	$addrec=$DB->query('select * from '. OT_dbPref .'vpsDealerList where VDL_ID='. $dataID);
		if (! $row = $addrec->fetch()){
			$alertMode='添加';
			$judRes = $DB->InsertParam('vpsDealerList',$record);
		}else{
			$alertMode='修改';
			$judRes = $DB->UpdateParam('vpsDealerList',$record,'VDL_ID='. $dataID);
		}
	unset($addrec);
		if ($judRes){
			$alertRes='成功';
		}else{
			$alertRes='失败';
		}

	Adm::AddLog(array(
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】'. $alertMode . $alertRes .'！',
		));

	JS::AlertHref(''. $alertMode .'成功！',$backURL);

}



// 删除
function del(){
	global $DB,$dataType,$dataTypeCN;

	$dataType	= OT::GetStr('dataType');
	$dataTypeCN	= OT::GetStr('dataTypeCN');
	$dataID		= OT::GetInt('dataID');
	$theme		= OT::GetStr('theme');

	if ($dataID<=0){
		JS::AlertEnd('指定ID错误.');
	}

	$useNum = $DB->GetOne('select count(SU_ID) from '. OT_dbPref .'servUsers where SU_dealerID='. $dataID);
		if ($useNum > 0){ JS::AlertEnd('该记录已有服务器租用占用，禁止删除！'); }

	$DB->query('delete from '. OT_dbPref .'vpsDealerList where VDL_ID='. $dataID);

	Adm::AddLog(array(
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】删除成功！',
		));

	echo('
	<script language="javascript" type="text/javascript">
	parent.$id("data'. $dataID .'").style.display="none";
	</script>
	');
}
?>